package com.kid.keep.dao.message;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kid.keep.bo.MessageBO;
import com.kid.keep.po.Message;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description Message dao
 * @Author JOHN
 * @Create 2019-01-10
 * @Since 1.0.0
 */
@Repository
public class MessageRepository extends ServiceImpl<IMessageMapper, Message> implements IMessageRepository {

    @Override
    public Integer countByTypeAndStatusAndCreatorId(Integer type, Integer status, Long creatorId) {
        return this.baseMapper.selectCount(new QueryWrapper<Message>().lambda().eq(Message::getType, type).eq(Message::getStatus, status).eq(Message::getCreatorId, creatorId));
    }

    @Override
    public Integer countByTypeAndCreatorId(Integer type, Long creatorId) {
        return this.baseMapper.selectCount(new QueryWrapper<Message>().lambda().eq(Message::getStatus, type).eq(Message::getCreatorId, creatorId));
    }

    @Override
    public Integer countByStatusAndCreatorId(Integer status, Long creatorId) {
        return this.baseMapper.selectCount(new QueryWrapper<Message>().lambda().eq(Message::getStatus, status).eq(Message::getCreatorId, creatorId));

    }

    @Override
    public List<MessageBO> findByTypeAndStatusAndCreatorId(Integer type, Integer status, Long creatorId) {
        return this.baseMapper.findByTypeAndStatusAndCreatorId(type,status,creatorId);
    }

    @Override
    public int updateStatusByIdAndCreatorId(Message message, Long id, Long creatorId) {
        return this.baseMapper.update(message,new UpdateWrapper<Message>().lambda().eq(Message::getId, id).eq(Message::getCreatorId, creatorId));
    }

    @Override
    public int updateAllStatusByStatusAndCreatorId(Message message, Integer status, Long creatorId) {
        return this.baseMapper.update(message,new UpdateWrapper<Message>().lambda().eq(Message::getStatus, status).eq(Message::getCreatorId, creatorId));
    }
}


